package com.cskaoyan;

import java.util.Random;

/**
 * @ClassName IPUtil
 * @Description: TODO
 * @Author 远志 zhangsong@cskaoyan.onaliyun.com
 * @Date 2022/1/14 10:13
 * @Version V1.0
 **/
public class IPUtil {

    private static int[][] range = {{607649792,608174079},
            {1038614528,1039007743},
            {1783627776,1784676351},
            {2035023872,2035154943},
            {2078801920,2079064063},
            {-1950089216,-1948778497},
            {-1425539072,-1425014785},
            {-1236271104,-1235419137},
            {-770113536,-768606209},
            {-569376768,-564133889},
    };

    public static String getRandomIpAddress(){
        Random rdint = new Random();
        int index = rdint.nextInt(10);
        String ip = num2ip(range[index][0]+new Random().nextInt(range[index][1]-range[index][0]));
        return ip;
    }

    private static String num2ip(int ip) {
        int [] b=new int[4] ;
        String x = "";
        b[0] = (int)((ip >> 24) & 0xff);
        b[1] = (int)((ip >> 16) & 0xff);
        b[2] = (int)((ip >> 8) & 0xff);
        b[3] = (int)(ip & 0xff);
        x=Integer.toString(b[0])+"."+Integer.toString(b[1])+"."+Integer.toString(b[2])+"."+Integer.toString(b[3]);
        return x;
    }

}
